<style>
.minicart_title {height:30px;line-height:30px;background:url(images/mincart_bj.gif) no-repeat;padding:0 6px}
.minicart_title ul {margin:0;padding:0;list-style-type:none}
.minicart_title li {float:left;padding:0 2px;background:url(images/mincart_icon.gif) no-repeat;padding-left:19px;margin-right:5px}
.minicart_title li.icon1 {background-position:0 9px;*background-position:0 8px}
.minicart_title li.icon2 {background-position:0 -16px}
</style>

<div class="minicart_<{$widgets_id}> minicart_box" <{if $setting.show_gallery}>show_gallery="true"<{/if}>>
  <div class="minicart_title"><ul><li class="icon1"><a href="<{link app=b2c ctl=site_cart act=index}>" target="cart_blank" class="cart-container"> <span class="cart-handle"><{t app="b2c"}>我的购物车<{/t}></span> </a></li><!--<li class="icon2"><span><a href="<{link app=b2c ctl=site_cart act=checkout}>">去结账</a></span></li>--></ul></div>
  <div class="MiniCarDetail minicart_cont"></div>
</div>
<script>
/*-------------
*minicart迷你购物车
-----------*/

window.addEvent('domready',function(){

    var cartViewUrl='<{link app=b2c ctl="site_cart" act="view"}>';
	var MiniCarWidgets={
		init:function(){
			var minicart=this.cart= $E('.minicart_<{$widgets_id}>'),
				minicart_detail=this.detailbox=$E('.MiniCarDetail',minicart),
				handle=this.handle=$E('.cart-handle',minicart);
			this.display().attach();
		},
		display:function(){
			<{if $setting.show_float}>
			var count=Cookie.read('S[CART_COUNT]')||0,display;
			display=!count.toInt()?'none':'';
			if(!!['form-cart','order-create',$E('.MemberCenter')].some(function(el){return $(el)}))display='none';
			this.cart.setStyle('display',display).setStyle('position','absolute').tween('top',document.body.getScroll().y+30);
			<{/if}>
			return this;
		},
		attach:function(){
			this.handle.addEvents({
				'mouseenter':function(e){
					if(this.state||!Cookie.read('S[CART_COUNT]'))return;
					this.request([{url:cartViewUrl, method:'post'}]);
					this.show();
				}.bind(this)
			});
			this.cart.addEvent('_show',function(e){
				this.handle.fireEvent('mouseenter');
			}.bind(this));
			window.addEvent('scroll',this.display.bind(this));
		},
		show:function(e){
			this.detailbox.setStyles({'visibility':'visible'});
			this.state=true;
			document.addEvent('click',function(){
				  this.hide();
                  document.removeEvent('click',arguments.callee);
		    }.bind(this));
		},
		hide:function(){
			this.state=false;
			this.detailbox.setStyle('visibility','hidden');
		},
		removeCart:function(el){
			var cartBox=el.getParent('.minicart-single'),self=this;	
			if(cartBox.hasClass('havechild')){
			   var chlid_id= cartBox.get('chlid_id'); 
			   if(group=$ES('.'+chlid_id,this.detailbox))
			   group.each(function(ell){ell.remove();});
		    }
			cartBox.destroy();
			this.request([{url:cartBox.get('urlremove'),data:this.detailbox,onComplete:function(re){
				var json=JSON.decode(re);
				$H(json).each(function(v,key){
					$E('.'+key,this.detailbox).set('html',v);	
				});
				MessageBox.success('删除成功');
			}.bind(this),onSuccess:function(){self.display();}}]);	
		},
		addEvent:function(){
			var _this=this;
			this.detailbox.getElements('.delcart').addEvent('click',function(e){
				e.stop(); _this.removeCart(this);
			});	
		},
		request:function(){
			var params=Array.flatten(arguments).link({
                 'remoteURL':String.type,
                 'options':Object.type
            });
			if(!params.options)return;
            params.options.data = (params.options.data?params.options.data.toQueryString():'')+'&mini_cart_list=true';
            if(!params.options.url)return false;
			params=$extend({
                 url:params.remoteURL,
                 method:'post',
                 onSuccess:function(re){
					 this.detailbox.empty().innerHTML=re;
					 this.display().addEvent();
                 }.bind(this)
             },params.options||{});
             return new Request(params).send();
		}
	};

	MiniCarWidgets.init();

	
});
</script>
